﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_FindBlurClient : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 35)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            TarreOA.TarreOAModels.User user=(User)Session["user"];
            if (user.ShellManager==1)
            {
                ddlSellUser.Items.Add(new ListItem("所有","1"));
                Label2.Text = "客户管理（客户总数 " + ClientManager.CountAllClient() + " ）";
            }
            else
            {
                Label2.Text = "客户管理（客户总数 " + ClientManager.CountAllClient(user.UserId) + " ）";
            }
            ddlSellUser.Items.Add(new ListItem("本人", "0"));
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Client client = new Client();
        if (ddlSellUser.SelectedValue == "0")
        {
            TarreOA.TarreOAModels.User user = (User)Session["user"];
            client.SellUser = user;
        }
        else
        {
            TarreOA.TarreOAModels.User user = new User();
            user.UserId = 0;
            client.SellUser = user;
        }
        client.IsShare = Convert.ToInt32(ddlIsShare.SelectedValue);
        if (txtClientName.Text != null && txtClientName.Text != "")
        {
            client.ClientName = txtClientName.Text;
        }
        else
        {
            client.ClientName = "";
        }
        if (txtTelephone.Text != null && txtTelephone.Text != "")
        {
            client.Telephone = txtTelephone.Text;
        }
        else 
        {
            client.Telephone = "";
        }
        if (txtFaxes.Text != null && txtFaxes.Text != "")
        {
            client.Faxes = txtFaxes.Text;
        }
        else
        {
            client.Faxes = "";
        }
        if (txtURL.Text != null && txtURL.Text != "")
        {
            client.Url = txtURL.Text;
        }
        else
        {
            client.Url = "";
        }
        if (txtEmail.Text != null && txtEmail.Text != "")
        {
            client.Email = txtEmail.Text;
        }
        else
        {
            client.Email = "";
        }
        if (txtAddress.Text != null && txtAddress.Text != "")
        {
            client.Address = txtAddress.Text;
        }
        else
        {
            client.Address = "";
        }
        if (txtPostalcode.Text != null && txtPostalcode.Text !="")
        {
            client.Postalcode = txtPostalcode.Text;
        }
        else
        {
            client.Postalcode = "";
        }
        if (txtRemark.Text !=null && txtRemark.Text !="")
        {
            client.Remark = txtRemark.Text;
        }
        else
        {
            client.Remark = "";
        }
        Session["client"] = client;
        Response.Redirect("ClientList.aspx");
    }
}
